﻿@model ChampionFramework.Models.Grupo
@{
    ViewBag.Title = "Details";
}
<h2>
    <span>Grupo </span>@Html.DisplayFor(model => model.Nome)</h2>
<p>
</p>
<fieldset>
    <legend>Grupo</legend>
    <div class="display-field">
        Times
    </div>
    @if (Model.Time.Count > 0)
    {
        <table>
            <tr>
                <th>
                    @Html.DisplayNameFor(model => model.Time.First().Nome)
                </th>
            </tr>
            @foreach (var item in Model.Time)
            {
                <tr>
                    <td>
                        @Html.DisplayFor(modelItem => item.Nome)
                    </td>
                </tr>
            }
        </table>
    }
</fieldset>
<fieldset>
    <legend>Jogos do grupo</legend>
    <table>
        <tr>
            <th>
                Mandante
            </th>
            <th>
                Visitante
            </th>
            <th>
                Data
            </th>
            <th>
                Horário
            </th>
            <th>
                Placar
            </th>
            <th>
            </th>
        </tr>
        @foreach (var item in Model.JogoGrupo)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.GetEscalacaoMandante().Time.Nome)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.GetEscalacaoVisitante().Time.Nome)
                </td>
                <td>
                    @String.Format("{0}/{1}/{2}", item.DataHora.Day, item.DataHora.Month, item.DataHora.Year)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.DataHora.TimeOfDay)
                </td>
                <td>
                    @String.Format("{0} x {1}", item.GetPlacar()[0], item.GetPlacar()[1])
                </td>
                <td>
                    @if(item.GetEscalacaoMandante().JogadorTitular.Count == 0)
                    {
                        @Html.ActionLink("Escalar times", "EscalarTimes", "JogoGrupo", new { id = item.Id }, null);
                    }
                    else if(!item.Encerrado)
                    {
                        @Html.ActionLink("Tempo real", "TempoReal", "JogoGrupo", new { id = item.Id }, null);
                    }
                </td>
            </tr>
        }
    </table>
</fieldset>
<p>
    @Html.ActionLink("Add Time", "AddTime", "Grupos", new { id = Model.Id }, null) |
    @Html.ActionLink("Add Game", "Create", "JogoGrupo", new { id = Model.Id }, null) |
    @Html.ActionLink("Back to Fases", "Index", "FaseGrupos", new object { }, null)
</p>
